#!/bin/sh
#
# This file shall be installed to folder /lib/systemd/system-sleep/:
# sudo sh -xvc 'f=zramswap.sh; d=/lib/systemd/system-sleep; [ -e $d/$f ] && exit 0; mkdir -p $d && cp -a $f $d/$f && f=$d/$f && chmod 0755 $f && chown 0:0 $f'
#
{
set -xv; echo "$0" "$@"; pwd; env
{ [ "suspend-then-hibernate" = "$2" ] || [ "hibernate" = "$2" ]; } && {
	[ "pre" = "$1" ] && {
		grep "^/dev/zram0 " /proc/swaps && swapoff -v /dev/zram0
		sync
		echo 1 > /proc/sys/vm/drop_caches
		exit 0
	}
	grep "^/dev/zram0 " /proc/swaps || swapon -v -p 9 /dev/zram0
}
} 2>&1 | logger -t zramswap.sh
exit 0

